package domain.player.ai;

import domain.GameGrid;
import domain.player.Disc;
import java.util.Random;

/**
 * Abstract class representing the "artificial intelligence" of the computer.
 */
public abstract class AI {

	/** Constants to keep track of the type of AI. */
	public final static int AI_HASHMAP = 0, AI_MINIMAX = 1, AI_MINMAX = 2;
	/** The player's Disc */
	private Disc discID;

	// Constructor.
	public AI(Disc discID) {
		this.discID = discID;
	}

	// Setters and getters.
	public Disc getDiscID() {
		return discID;
	}

	public void setDiscID(Disc disc) {
		discID = disc;
	}

	/**
	 * Gets the best move the player can do, that the the AI can find.
	 *
	 * @return The column the player should choose for its next move.
	 */
	public abstract int getGoodMove(GameGrid grid);

	/** Returns the type of AI. */
	public abstract int getType();

	/**
	 * Picks a random column.
	 *
	 * @return A column represented by an int.
	 */
	public int pickRandomColumn(GameGrid gameGrid) {
		int move;
		Random random = new Random();
		while (true) {
			move = random.nextInt(GameGrid.GRID_COLUMNS);
			if (gameGrid.isValidMove(move) || gameGrid.isTie()) {
				break;
			}
		}

		System.out.println("AI: random move: " + move);
		return move;
	}
}
